package com.example.androidhive;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Logowanie extends Activity {

	// Progress Dialog
	private ProgressDialog pDialog;

	JSONParser jsonParser = new JSONParser();
	EditText mojekontohaslo_;

	// url to create new product
	private static String url_create_product ="http://opiekuj1.javaprovider.net/php/logowanie.php";
	private static String url_create_product2 ="http://opiekuj1.javaprovider.net/php/rezerwa.php";

	// JSON Node names
	private static final String TAG_SUCCESS = "success";
	Context c_;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mojekonto);

		// Edit Text
		
		// Create button
		Button btnCreateProduct1 = (Button) findViewById(R.id.btnotworz);
		// button click event
		btnCreateProduct1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent i;
				i = new Intent(getApplicationContext(), Polozenie.class);
				startActivity(i);
				/*Editable aa1 = ((EditText) findViewById(R.id.mojekontohaslo)).getText();
				final String b=		aa1.toString();
				String[] c={"logowanie","nazwa-"+b+" mm-o"};
				Base_ aa=new Base_(Logowanie.this,c,c_);
				aa.execute();*/
			}
		});
		/*Button btnCreateProduct2 = (Button) findViewById(R.id.btnotworz2);
		// button click event
		btnCreateProduct2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				// creating new product in background thread
				new CreateNewProductR().execute();
			}
		});*/
	}
	class CreateNewProductR extends AsyncTask<String,String,String> {

		/**
		 * Before starting background thread Show Progress Dialog
		 * */
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(Logowanie.this);
			pDialog.setMessage("Rezerwowanie..");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(true);
			pDialog.show();
		}

		/**
		 * Creating product
		 * */
		protected String doInBackground(String... args) {
			List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("nazwa", "mm"));
			JSONObject json = jsonParser.makeHttpRequest(url_create_product2,
					"POST", params);
			
			// check log cat fro response
			Log.d("Create Response", json.toString());

			// check for success tag
			try {
				int success = json.getInt(TAG_SUCCESS);

			} catch (JSONException e) {
				e.printStackTrace();
			}

			return null;
		}

		/**
		 * After completing background task Dismiss the progress dialog
		 * **/
		protected void onPostExecute(String file_url) {
			// dismiss the dialog once done
			pDialog.dismiss();
		}

	}
	
}

